.extern ____sched_curthread
.extern iroute_stub
.extern g_k_vmd
.global iroute_stub86
iroute_stub86:
# save state
push %ds
push %es
push %fs
push %gs

# save user stack and load kernel stack
movl ____sched_curthread, %edx
movl %esp, (%edx)
movl 4(%edx), %esp

xchg %eax, %ebx

# load kernel cr3
mov (g_k_vmd), %eax
mov %eax, %cr3
mov %cr0, %eax
or $0x80000000, %eax
mov %eax, %cr0

push %ebx

call iroute_stub

# discard kernel stack and load user stack
movl ____sched_curthread, %edx
movl (%edx), %esp

# load new cr3 and enable paging.
mov 8(%edx), %eax
mov %eax, %cr3
mov %cr0, %eax
or $0x80000000, %eax
mov %eax, %cr0

# restore state
pop %gs
pop %fs
pop %es
pop %ds
popa
iret


